package com.service.Impl;

import com.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;

import java.util.UUID;

//@Service：这里不需要了，这里不是传统的controller调用service。这个service是和rabbitMQ打交道的
@EnableBinding(Source.class) //可以理解为我们定义一个消息生产者的发送管道
public class IMessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output; //消息放送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        //通过output这个管道向消息中间件发送消息
        Message<String> message = MessageBuilder.withPayload(serial).build();
        output.send(message);

        //output.send(MessageBuilder.withPayload(serial).build());

        System.out.println("*********serial: " + serial);

        return null;
    }
}
